<template>
    <div>
        <h1>分配权益</h1>
      <table class="table">
         <tbody>
            <tr>
            <td>等级名称</td>
            <td>
                <input type="text" v-model="data.levelName">
            </td>
        </tr>
        <tr>
            <td>权益名称</td>
            <td>
                <select v-model="data.quanyiid">
            <option value="0">请选择权益</option>
            <option v-for="e in XLK"  :value="e.id">{{ e.quanyiName }}</option>
        </select>
               
            </td>
        </tr>

        <tr>
            <td>状态</td>
            <td> <input type="checkbox" v-model="data.state" checked>选择为启用,未选择未禁用</td>
        </tr>
        <tr>
            <td colspan="2"><input type="button" value="添加会员权益" @click="add"></td>
        </tr>
         </tbody>
      </table>
        
    </div>
</template>

<script setup lang="ts">
import {ref,onMounted} from 'vue'
import axios from 'axios';
import { useRouter,useRoute  } from 'vue-router';

const router=useRouter();
const route=useRoute();

onMounted(()=>{
    getid();
    XLKS();
})

const data = ref({
  "id": 0,
  "levelName": "",
  "state": true,
  "quanyiid": 0
})
 
var hh=ref(["免费洗车","免费早饭","八折","五折"])
var h=ref([])

//下拉框
const XLK=ref([{
    "id": 3,
    "quanyiName": "免费早饭",
    "qstate": true
  }])

const XLKS=()=>{
    axios.get("https://localhost:7065/api/LevelMember/GetQuan").then(res=>{
      XLK.value=res.data
    })
}

const add=()=>{
    axios.put("https://localhost:7065/api/LevelQuanyi/Update",data.value).then(res=>{
          if(res.data>0)
          {
              alert("会员权益添加成功");
              router.push({path:"/lshow"})
          } 
          else{
            alert("会员权益添加失败");
            return;
          }
    })
}

const getid=()=>{
    var vid = route.query.id;
    axios.get("https://localhost:7065/api/LevelQuanyi/Getid",{params:{id:vid}}).then(res=>{
        data.value=res.data;
    })
}


</script>

<style scoped>

</style>